<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button class="btn">按钮一</button>
    <button class="btn">按钮二</button>
    <button class="btn">按钮三</button>
    <div class="container"></div>
    <script>
      var btns = document.getElementsByTagName("button");
      var containerEle = document.getElementsByClassName("container")[0];
      btns[0].onclick = function () {
        window.location.hash = "a";
        // containerEle.innerHTML = "hello";  //替换 containerEle标签里的内容；

        renderdom();
      };
      btns[1].onclick = function () {
        window.location.hash = "b";
        // containerEle.innerHTML = "hello";  //替换 containerEle标签里的内容；

        renderdom();
      };
      btns[2].onclick = function () {
        window.location.hash = "c";
        // containerEle.innerHTML = "hello";  //替换 containerEle标签里的内容；

        renderdom();
      };
      function renderdom() {
        var hashStr = window.location.hash;
        switch (hashStr) {
          case "#a":
            containerEle.innerHTML = "第一个页面";
            break;

          case "#b":
            containerEle.innerHTML = "第二个页面";
            break;

          case "#c":
            containerEle.innerHTML = "第三个页面";
            break;
          default:
            console.log("哈希值错误");
            break;
        }
      }
    </script>
  </body>
</html>
